﻿using System;
using System.Threading.Tasks;
using ERP.Workflow.Designer.Application.Contracts;
using ERP.Workflow.Designer.BlazorUI.Menus;
using ERP.Workflow.Designer.Domain.Shared.Localization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.UI.Navigation;
using Volo.Abp.Users;

namespace ERP.Workflow.Designer.BlazorUI.Menus;
public class WorkflowDesignerMenuContributor : IMenuContributor
{
    private readonly IConfiguration _configuration;

    public WorkflowDesignerMenuContributor(IConfiguration configuration)
    {
        _configuration = configuration;
    }
    public async Task ConfigureMenuAsync(MenuConfigurationContext context)
    {
            await ConfigureMainMenuAsync(context);
    }

    private Task ConfigureMainMenuAsync(MenuConfigurationContext context)
    {
        /*
        var l = context.GetLocalizer<WorkflowDesignerResource>();
        context.Menu.Items.Insert(
         0, new ApplicationMenuItem(WorkflowDesignerMenus.FlowMg, displayName: l["Menu:FlowMmanager"], "#", icon: "branches", requiredPermissionName: WorkflowDesignerPermissions.FlowMg) 
             .AddItem(new ApplicationMenuItem(name: WorkflowDesignerMenus.Designer, displayName: l["Menu:FlowDesigner"], url: $"workflow/designer/list", icon: "form", requiredPermissionName: WorkflowDesignerPermissions.Designer)) 
             .AddItem(new ApplicationMenuItem(name: WorkflowDesignerMenus.Applicatoin, displayName: l["Menu:FlowApplicatoin"], url: $"test2?a={new Random().NextDouble()}", icon: "codepen", requiredPermissionName: WorkflowDesignerPermissions.Applicatoin) )
            // .AddItem(new ApplicationMenuItem(name:FlowMenus.Instance, displayName: l["Menu:FlowInstance"], url: $"test2?a={new Random().NextDouble()}", icon: "bars", requiredPermissionName: ERPPermissions.Instance) )
        );
        */
        
        var l = context.GetLocalizer<WorkflowDesignerResource>();
        context.Menu.Items.Insert(
         0, new ApplicationMenuItem(WorkflowDesignerMenus.FlowMg, displayName: l["Menu:FlowMmanager"], "#", icon: "branches" )
             .AddItem(new ApplicationMenuItem(name: WorkflowDesignerMenus.Designer, displayName: l["Menu:FlowDesigner"], url: $"workflow/designer/list", icon: "form" ))
             .AddItem(new ApplicationMenuItem(name: WorkflowDesignerMenus.Applicatoin, displayName: l["Menu:FlowApplicatoin"], url: $"test2?a={new Random().NextDouble()}", icon: "codepen" ))
        // .AddItem(new ApplicationMenuItem(name:FlowMenus.Instance, displayName: l["Menu:FlowInstance"], url: $"test2?a={new Random().NextDouble()}", icon: "bars", requiredPermissionName: ERPPermissions.Instance) )
        );
        
        return Task.CompletedTask;
    }
}

